package com.sgb.businessmodule.view.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.PopupWindow;
import android.widget.TextView;

import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.sgb.businessmodule.R;
import com.sgb.businessmodule.databinding.ActivityBusinessOpportunityHallBinding;
import com.sgb.businessmodule.entity.BusinessRequestEntity;
import com.sgb.businessmodule.entity.HomeBusinessListEntity;
import com.sgb.businessmodule.entity.PickFilterEntity;
import com.sgb.businessmodule.view.ui.adapter.AdapterJumpPush;
import com.sgb.businessmodule.view.ui.adapter.BusinessChildTabAdapter;
import com.sgb.businessmodule.view.ui.adapter.BusinessTabAdapter;
import com.sgb.businessmodule.view.ui.adapter.HomeBusinessAdapter;
import com.sgb.businessmodule.view.widget.BudgetAmountPopWindow;
import com.sgb.businessmodule.view.widget.BusinessSelectionTypePopWindow;
import com.sgb.businessmodule.view.widget.PopularBusinessFilterPopWindow;
import com.sgb.businessmodule.view.widget.TwoLevelMultipleChoiceWindow;
import com.sgb.businessmodule.viewmodel.BusinessOpportunityHallModel;
import com.swgk.core.base.AppActivity;
import com.swgk.core.base.aroute.AppRouteConstant;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.recyclerview.decoration.RecyclerCustomDecoration;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.view.countmenu.CountMenuEntity;
import com.swgk.core.view.selectdate.DatePopupWindow;
import com.swgk.core.view.selection.MemberStatusView;
import com.swgk.core.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Objects;

/**
 * @author 李伟
 * @date 2021/8/10 18:20
 * @Description 商机大厅界面
 */
@Route(path = AppRouteConstant.ShangJi.ROUTER_PATH_SJ_BUSINESS_OPPORTUNITY_HALL)
public class BusinessOpportunityHallActivity extends AppActivity {
    private ActivityBusinessOpportunityHallBinding mBinding;
    private BusinessOpportunityHallModel mViewModel;
    private HomeBusinessAdapter homeBusinessAdapter;
    private BusinessTabAdapter tabAdapter;
    private BusinessChildTabAdapter childTabAdapter;

    private BusinessRequestEntity requestEntity;
    private boolean isLoadMore = false;
    private int currentPage = 1;
    private int currentIndex = 0;
    private List<String> currentNoList = new ArrayList<>();
    private List<String> businessStyleList = new ArrayList<>();
    private String mMinBudget;
    private String mMaxBudget;
    private String mTimeStart;
    private String mTimeEnd;
    private String currentFirstNo;
    private String currentSecNo;
    private int currentChildIndex = 0;
    private Boolean publishTime;
    private Boolean budgetAmount;
    private Boolean endTime;

    //日常选择器
    private DatePopupWindow datePopupWindow;

    //商机分类二级联动数据
    private List<PickFilterEntity<List<PickFilterEntity>>> categoryList;

    //省市二级联动数据
    List<PickFilterEntity<List<PickFilterEntity>>> cityFilterList;
    //所选省区域数据
    private PickFilterEntity provinceEntity;
    //所选市区域的集合数据
    private List<PickFilterEntity> cityEntityList;
    //省市二级联动PopWindow
    private TwoLevelMultipleChoiceWindow choiceWindow;

    //预算金额筛选器
    private BudgetAmountPopWindow amountPopWindow;

    //侧面滑动筛选
    private PopularBusinessFilterPopWindow filterPopWindow;
    //大厅二级类目下拉弹框
    private BusinessSelectionTypePopWindow mPopWindow;

    /**
     * @param context  上下文
     * @param position 点击事件Item所处的位置
     * @param no       获取类别No实现数据初始化加载
     */
    public static void start(Context context, int position, String no) {
        Intent intent = new Intent();
        intent.putExtra("index", position);
        intent.putExtra("no", no);
        intent.setClass(context, BusinessOpportunityHallActivity.class);
        context.startActivity(intent);
    }

    /**
     * @param context  上下文
     * @param mKeyWord 搜索关键字
     */
    public static void start(Context context, String mKeyWord) {
        Intent intent = new Intent();
        intent.putExtra("index", 0);
        intent.putExtra("no", "");
        intent.putExtra("mKeyWord", mKeyWord);
        intent.setClass(context, BusinessOpportunityHallActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_business_opportunity_hall);
        mViewModel = new ViewModelProvider(this).get(BusinessOpportunityHallModel.class);
        mBinding.topLayout.ivBack.setOnClickListener(this::onClick);
        initEtSearchView();
        mBinding.businessTime.setOnClickListener(this::onClick);
        mBinding.businessAddress.setOnClickListener(this::onClick);
        mBinding.businessMoney.setOnClickListener(this::onClick);
        mBinding.option.setOnClickListener(this::onClick);
        mBinding.ivPopup.setOnClickListener(this::onClick);
        if (getIntent() != null) {
            currentIndex = getIntent().getIntExtra("index", 0);
            String no = getIntent().getStringExtra("no");
            String mKeyWord = getIntent().getStringExtra("mKeyWord");
            if (!TextUtils.isEmpty(no)) {
                currentFirstNo = no;
            }
            if (!TextUtils.isEmpty(mKeyWord)) {
                mBinding.topLayout.etView.setText(mKeyWord);
            }
        }

        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        mBinding.recyclerView.setLayoutManager(layoutManager);
        mBinding.recyclerView.addItemDecoration(new RecyclerCustomDecoration(0,
                0,
                0,
                getResources().getDimension(R.dimen.dp1)));
        if (homeBusinessAdapter == null) {
            homeBusinessAdapter = new HomeBusinessAdapter(getActivity(), null);
            homeBusinessAdapter.setOnItemClick(new AdapterOnItemClick<HomeBusinessListEntity>() {
                @Override
                public void onItemClick(HomeBusinessListEntity entity, int position) {
                    AdapterJumpPush.getInstance(getActivity(), entity, new AdapterJumpPush.CallBack() {
                        @Override
                        public void doBack() {
                            homeBusinessAdapter.getDatas().remove(entity);
                            homeBusinessAdapter.notifyDataSetChanged();
                        }
                    });
                }
            });
        }
        mBinding.recyclerView.setAdapter(homeBusinessAdapter);
        mBinding.recyclerView.setPullRefreshEnabled(false);
        mBinding.recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
            }

            @Override
            public void onLoadMore() {
                loadData(true);
            }
        });

        if (filterPopWindow == null) {
            filterPopWindow = new PopularBusinessFilterPopWindow(this);
        }
        cityFilterList = new ArrayList<>();
        cityEntityList = new ArrayList<>();
        provinceEntity = new PickFilterEntity("", "不限");

        //初始化所有数据监听
        initObserve();
        //获取商机分类四级联动数据
        mViewModel.requestBusinessTypeData();
        //获取省市二级联动数据
        mViewModel.getCityList();
        //获取商机分类二级联动数据
        mViewModel.requestBusinessType2Data();
    }

    /**
     * 初始化 首页搜索功能
     */
    private void initEtSearchView() {
        mBinding.topLayout.tvSearch.setOnClickListener(this::onClick);
        mBinding.topLayout.etView.setOnKeyListener(new View.OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
                    loadData(false);
                }
                return false;
            }
        });
    }

    private void initObserve() {
        //顶部菜单栏数据返回监听
        mViewModel.countMenuList.observe(this, new Observer<List<CountMenuEntity>>() {
            @Override
            public void onChanged(List<CountMenuEntity> countMenuEntities) {
                initMenuRecycler(countMenuEntities);
            }
        });
        //大厅列表数据返回监听
        mViewModel.businessList.observe(this, new Observer<List<HomeBusinessListEntity>>() {
            @Override
            public void onChanged(List<HomeBusinessListEntity> homeBusinessListEntities) {
                showList(homeBusinessListEntities);
            }
        });
        //商机类型列表数据返回监听
        mViewModel.businessStyleList.observe(this, new Observer<List<PickFilterEntity>>() {
            @Override
            public void onChanged(List<PickFilterEntity> pickFilterEntities) {
                filterPopWindow.setBusinessStyleData(pickFilterEntities);
            }
        });
        //省市列表数据返回监听
        mViewModel.addressList.observe(this, new Observer<List<PickFilterEntity<List<PickFilterEntity>>>>() {
            @Override
            public void onChanged(List<PickFilterEntity<List<PickFilterEntity>>> pickFilterEntities) {
                cityFilterList.addAll(pickFilterEntities);
                filterPopWindow.setAddressData(pickFilterEntities, 0, null);
            }
        });
        //商机分类四级联动数据返回监听
        mViewModel.businessTypeList.observe(this, new Observer<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>>>() {
            @Override
            public void onChanged(List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>> pickFilterEntities) {
                filterPopWindow.setBusinessTypeData(pickFilterEntities);
            }
        });
        //获取商机分类二级联动数据
        mViewModel.businessType2List.observe(this, new Observer<List<PickFilterEntity<List<PickFilterEntity>>>>() {
            @Override
            public void onChanged(List<PickFilterEntity<List<PickFilterEntity>>> pickFilterEntities) {
                initChildRecycler(pickFilterEntities);
            }
        });
    }

    private void loadData(boolean isLoadMore) {
        this.isLoadMore = isLoadMore;
        if (isLoadMore) {
            currentPage++;
        } else {
            currentPage = 1;
        }
        requestEntity = new BusinessRequestEntity();
        requestEntity.setPage(currentPage);
        requestEntity.setLimit(20);
        BusinessRequestEntity.SortFieldBean bean = new BusinessRequestEntity.SortFieldBean();
        if (publishTime != null) {
            bean.setPublishTime(publishTime);
        } else if (budgetAmount != null) {
            bean.setBudgetAmount(budgetAmount);
        } else if (endTime != null) {
            bean.setEndTime(endTime);
        } else {
            bean.setPublishTime(false);
        }
        requestEntity.setSortField(bean);
        currentNoList.clear();
        if (!TextUtils.isEmpty(currentFirstNo)) {
            currentNoList.add(currentFirstNo);
        }
        if (!TextUtils.isEmpty(currentSecNo)) {
            currentNoList.add(currentSecNo);
        }
        if (currentNoList.size() > 0) {
            requestEntity.setCategories(currentNoList);
        }
        if (cityEntityList.size() > 0) {
            List<String> cityNoList = new ArrayList<>();
            for (PickFilterEntity entity : cityEntityList) {
                if (!TextUtils.isEmpty(entity.getNo())) {
                    cityNoList.add(entity.getNo());
                }
            }
            if (cityNoList.size() > 0) {
                requestEntity.setCityNo(cityNoList);
            }
        } else {
            if (!TextUtils.isEmpty(provinceEntity.getNo())) {
                requestEntity.setProvinceNo(provinceEntity.getNo());
            }
        }
        if (!TextUtils.isEmpty(getKeyWord())) {
            mViewModel.setShardHistorySearch(getKeyWord());
            requestEntity.setKeyword(getKeyWord());
        }
        if (businessStyleList.size() > 0) {
            requestEntity.setOpportunityTypeNo(businessStyleList);
        }
        if (!TextUtils.isEmpty(mMinBudget)) {
            requestEntity.setBudgetAmountStart(mMinBudget);
        }
        if (!TextUtils.isEmpty(mMaxBudget)) {
            requestEntity.setBudgetAmountEnd(mMaxBudget);
        }
        if (!TextUtils.isEmpty(mTimeStart)) {
            requestEntity.setPublishTimeStart(mTimeStart);
        }
        if (!TextUtils.isEmpty(mTimeEnd)) {
            requestEntity.setPublishTimeEnd(mTimeEnd);
        }
        mViewModel.requestBusinessListData(requestEntity);
    }

    /*
     * 大厅菜单栏
     * */
    private void initMenuRecycler(List<CountMenuEntity> list) {
        tabAdapter = new BusinessTabAdapter(this, list);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        mBinding.tabRecycler.setLayoutManager(manager);
        mBinding.tabRecycler.setAdapter(tabAdapter);
        tabAdapter.setOnItemClick(new AdapterOnItemClick<CountMenuEntity>() {
            @Override
            public void onItemClick(CountMenuEntity entity, int position) {
                currentIndex = position;
                tabAdapter.setCurrentSelected(entity.getName());
                businessStyleList.clear();
                if (entity.getName().equals("全部")) {
                    currentNoList.clear();
                    currentFirstNo = "";
                } else {
                    currentFirstNo = entity.getId();
                }
                initChildRecycler(null);
                loadData(false);
            }
        });

        //默认请求全部分类的数据
        loadData(false);
        //根据点击的位置来定位RecyclerView的滚动位置
        mBinding.tabRecycler.scrollToPosition(currentIndex);
        tabAdapter.setCurrentSelected(list.get(currentIndex).getName());
    }

    /*
     * 大厅菜单栏二级类目
     * */
    private void initChildRecycler(List<PickFilterEntity<List<PickFilterEntity>>> list) {
        currentSecNo = "";
        if (categoryList == null) {
            categoryList = new ArrayList<>();
            categoryList.clear();
            categoryList.addAll(list);
        }
        if (currentIndex == 0) {
            mBinding.linChildRecycler.setVisibility(View.GONE);
            return;
        } else {
            mBinding.linChildRecycler.setVisibility(View.VISIBLE);
        }
        if (categoryList.get(currentIndex) != null) {
            currentChildIndex = 0;
            List<PickFilterEntity> data = categoryList.get(currentIndex).getChildren();
            if (data.size() > 0 && !data.get(0).getName().equals("全部")) {
                data.add(0, new PickFilterEntity("", "全部"));
            }
            if (data.size() < 4) {
                mBinding.ivPopup.setVisibility(View.GONE);
            } else {
                mBinding.ivPopup.setVisibility(View.VISIBLE);
            }
            childTabAdapter = new BusinessChildTabAdapter(this, data);
            LinearLayoutManager manager = new LinearLayoutManager(this);
            manager.setOrientation(LinearLayoutManager.HORIZONTAL);
            mBinding.tabChildRecycler.setLayoutManager(manager);
            mBinding.tabChildRecycler.setAdapter(childTabAdapter);
            childTabAdapter.setOnItemClick(new AdapterOnItemClick<PickFilterEntity>() {
                @Override
                public void onItemClick(PickFilterEntity entity, int position) {
                    currentChildIndex = position;
                    childTabAdapter.setCurrentSelected(entity.getName());
                    currentSecNo = entity.getNo();
                    loadData(false);
                }
            });
        } else {
            mBinding.linChildRecycler.setVisibility(View.GONE);
        }
    }

    @Override
    protected void init() {
        //获取顶部菜单栏数据
        mViewModel.requestBusinessMenuData();
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.iv_back) {
            finish();
        } else if (v.getId() == R.id.tv_search) {
            loadData(false);
        } else if (v.getId() == R.id.business_time) {
            createCustomDatePicker(mBinding.businessTime, mBinding.businessTime);
        } else if (v.getId() == R.id.business_address) {
            if (!cityFilterList.isEmpty()) {
                showAddressPopWindow(cityFilterList);
            } else {
                mViewModel.getCityList();
            }
        } else if (v.getId() == R.id.option) {
            showPopularFilterPopWindow();
        } else if (v.getId() == R.id.business_money) {
            showBudgetPopWindow();
        } else if (v.getId() == R.id.ivPopup) {
            showPopup();
        }
    }

    /*
     * 获取当前搜索框的关键词
     * */
    private String getKeyWord() {
        return mBinding.topLayout.etView.getText().toString().trim();
    }

    public void showList(List<HomeBusinessListEntity> list) {
        if (isLoadMore) {
            if (list != null && list.size() > 0) {
                homeBusinessAdapter.addDatas(list);
            }
            mBinding.recyclerView.setNoMore(mViewModel.isLastPage);
            mBinding.recyclerView.setVisibility(View.VISIBLE);
        } else {
            mBinding.recyclerView.refreshComplete();
            if (list != null && list.size() > 0) {
                mBinding.emptyView.setVisibility(View.GONE);
                homeBusinessAdapter.setDatas(list);
                mBinding.recyclerView.smoothScrollToPosition(0);
                mBinding.recyclerView.setNoMore(mViewModel.isLastPage);
            } else {
                homeBusinessAdapter.clearDatas();
                mBinding.emptyView.setVisibility(View.VISIBLE);
            }
        }
    }

    /*
     * 日期选择器
     * */
    private void createCustomDatePicker(View view, TextView result) {
        if (datePopupWindow == null) {
            datePopupWindow = new DatePopupWindow
                    .Builder(this, Calendar.getInstance().getTime(), view)
                    .setDateOnClickListener(new DatePopupWindow.DateOnClickListener() {
                        @Override
                        public void getDate(Long startDate, Long endDate) {
                            if (startDate != 0) {
                                mTimeStart = String.valueOf(startDate);
                                mTimeEnd = String.valueOf(endDate);
                            } else {
                                mTimeStart = "";
                                mTimeEnd = "";
                            }
                            loadData(false);
                        }

                        @Override
                        public void onDismiss() {
                            if (TextUtils.isEmpty(mTimeStart)) {
                                setTextViewChange(mBinding.businessTime, R.mipmap.ic_down_arrow_n, R.color.color_666666, false);
                            } else {
                                setTextViewChange(mBinding.businessTime, R.mipmap.ic_down_arrow, R.color.color_main, true);
                            }
                        }
                    }).builder();
        } else {
            datePopupWindow.showDatePopupWindow(mBinding.businessTime, mTimeStart, mTimeEnd);
        }
        setTextViewChange(mBinding.businessTime, R.mipmap.ic_down_arrow_u, R.color.color_666666, false);
    }

    /*
     * 地区选择器(多选)
     * */
    public void showAddressPopWindow(List<PickFilterEntity<List<PickFilterEntity>>> list) {
        if (choiceWindow == null) {
            choiceWindow = new TwoLevelMultipleChoiceWindow(this);
            choiceWindow.setBgView(mBinding.grayLayout);
            choiceWindow.setOnResultClick(new TwoLevelMultipleChoiceWindow.OnResultClick() {
                @Override
                public void result(PickFilterEntity entity, List<PickFilterEntity> list) {
                    provinceEntity.replaceData(entity);
                    if (TextUtils.isEmpty(provinceEntity.getNo())) {
                        cityEntityList.clear();
                        mBinding.businessAddress.setText("地区");
                    } else {
                        if (list != null && list.size() > 0 && !list.get(0).getName().equals("不限")) {
                            cityEntityList.clear();
                            cityEntityList.addAll(list);
                        } else {
                            cityEntityList.clear();
                        }
                        //mBinding.businessAddress.setText(provinceEntity.getName());
                    }
                    loadData(false);
                }
            });
            choiceWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    if (provinceEntity == null) {
                        setTextViewChange(mBinding.businessAddress, R.mipmap.ic_down_arrow_n, R.color.color_666666, false);
                    } else {
                        if (provinceEntity.getNo() != null && TextUtils.isEmpty(provinceEntity.getNo())) {
                            setTextViewChange(mBinding.businessAddress, R.mipmap.ic_down_arrow_n, R.color.color_666666, false);
                            return;
                        }
                        setTextViewChange(mBinding.businessAddress, R.mipmap.ic_down_arrow, R.color.color_main, true);
                    }
                }
            });
        }
        if (TextUtils.isEmpty(provinceEntity.getNo())) {
            choiceWindow.setData(list, 0, cityEntityList);
        } else {
            if (cityEntityList.size() != 0) {
                choiceWindow.setData(list, -1, cityEntityList);
            } else {
                choiceWindow.setData(list, getCurrentAddress(provinceEntity.getNo()) + 1, cityEntityList);
            }
        }
        setTextViewChange(mBinding.businessAddress, R.mipmap.ic_down_arrow_u, R.color.color_666666, false);
        choiceWindow.showPopwindow0(mBinding.layoutTag);
    }

    /*
     * 预算金额筛选器
     * */
    public void showBudgetPopWindow() {
        if (amountPopWindow == null) {
            amountPopWindow = new BudgetAmountPopWindow(this);
            amountPopWindow.setBgView(mBinding.grayLayout);
            amountPopWindow.setOnResultClick(new BudgetAmountPopWindow.OnResultClick() {
                @Override
                public void result(String minBudget, String maxBudget) {
                    mMinBudget = minBudget;
                    mMaxBudget = maxBudget;
                    loadData(false);
                }
            });
            amountPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    if (TextUtils.isEmpty(mMinBudget)) {
                        setTextViewChange(mBinding.businessMoney, R.mipmap.ic_down_arrow_n, R.color.color_666666, false);
                    } else {
                        setTextViewChange(mBinding.businessMoney, R.mipmap.ic_down_arrow, R.color.color_main, true);
                    }
                }
            });
        }
        setTextViewChange(mBinding.businessMoney, R.mipmap.ic_down_arrow_u, R.color.color_666666, false);
        mBinding.businessMoney.setSelected(false);
        amountPopWindow.showPopwindow0(mBinding.layoutTag);
    }

    /*
     * 右侧滑动筛选器
     * */
    public void showPopularFilterPopWindow() {
        filterPopWindow.setFilterResultClick(new PopularBusinessFilterPopWindow.FilterResultClick() {
            @Override
            public void result(List<PickFilterEntity> a, List<PickFilterEntity> b, PickFilterEntity c, List<PickFilterEntity> d, PickFilterEntity e) {
                currentNoList.clear();
                businessStyleList.clear();
                for (PickFilterEntity entity : a) {
                    if (!TextUtils.isEmpty(entity.getNo()))
                        currentNoList.add(entity.getNo());
                }
                for (PickFilterEntity entity : b) {
                    if (!TextUtils.isEmpty(entity.getNo()))
                        businessStyleList.add(entity.getNo());
                }

                provinceEntity.replaceData(c);

                if (TextUtils.isEmpty(c.getName())) {
                    setTextViewChange(mBinding.businessAddress, R.mipmap.ic_down_arrow_n, R.color.color_666666, false);
                } else {
                    setTextViewChange(mBinding.businessAddress, R.mipmap.ic_down_arrow, R.color.color_main, true);
                }

                cityEntityList.clear();
                if (d != null && d.size() > 0) {
                    cityEntityList.addAll(d);
                }

                publishTime = null;
                budgetAmount = null;
                endTime = null;
                switch (e.getNo()) {
                    case "1":
                        publishTime = false;
                        break;
                    case "2":
                        publishTime = true;
                        break;
                    case "3":
                        budgetAmount = true;
                        break;
                    case "4":
                        budgetAmount = false;
                        break;
                    case "5":
                        endTime = true;
                        break;
                    case "6":
                        endTime = false;
                        break;
                }
                loadData(false);
            }

            @Override
            public void echoStatus(int a, String nameA, int b, String nameB) {
                currentIndex = a;
                mBinding.tabRecycler.scrollToPosition(a);
                if (a == 0) {
                    tabAdapter.setCurrentSelected("全部");
                    mBinding.linChildRecycler.setVisibility(View.GONE);
                } else {
                    initChildRecycler(null);
                    if (b != 0) {
                        currentChildIndex = b;
                        childTabAdapter.setCurrentSelected(nameB);
                        mBinding.tabChildRecycler.scrollToPosition(b);
                    }
                    tabAdapter.setCurrentSelected(nameA);
                }
            }
        });
        filterPopWindow.setIndex(currentIndex, currentChildIndex);
        if (TextUtils.isEmpty(provinceEntity.getNo())) {
            filterPopWindow.setAddressData(cityFilterList, 0, cityEntityList);
        } else {
            if (cityEntityList.size() != 0) {
                filterPopWindow.setAddressData(cityFilterList, -1, cityEntityList);
            } else {
                filterPopWindow.setAddressData(cityFilterList, getCurrentAddress(provinceEntity.getNo()) + 1, cityEntityList);
            }
        }
        filterPopWindow.backgroundAlpha(0.5f);
        filterPopWindow.showPopwindowRight(mBinding.option);
    }

    private int getCurrentAddress(String provinceNo) {
        if (cityFilterList.size() > 0) {
            for (PickFilterEntity entity : cityFilterList) {
                if (entity.getNo().equals(provinceNo)) {
                    return cityFilterList.lastIndexOf(entity);
                }
            }
        }
        return 0;
    }

    private void setTextViewChange(TextView textView, int img, int textColor, boolean isSelected) {
        Drawable drawable = ContextCompat.getDrawable(this, img);
        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            textView.setCompoundDrawables(null, null, drawable, null);
            textView.setTextColor(ContextCompat.getColor(this, textColor));
            textView.setSelected(isSelected);
        }
    }

    /**
     * 根据分类类别No获取商机类型列表数据
     */
    public void requestBusinessStyleListData(String no) {
        mViewModel.requestBusinessStyleListData(no);
    }

    //展开弹窗
    private void showPopup() {
        if (mPopWindow == null) {
            mPopWindow = new BusinessSelectionTypePopWindow(getActivity());
            mPopWindow.setBgView(mBinding.grayLayout);
            mPopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
                @Override
                public void result(Object key1, Object key2, Object key3) {
                    currentChildIndex = (int) key2;
                    mBinding.ivPopup.setImageResource(R.mipmap.btn_shop_down);
                    mBinding.tabChildRecycler.scrollToPosition((int) key2);
                    childTabAdapter.setCurrentSelected(((PickFilterEntity) key1).getName());
                    currentSecNo = ((PickFilterEntity) key1).getNo();
                    loadData(false);
                }
            });
            mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    mBinding.ivPopup.setImageResource(R.mipmap.btn_shop_down);
                }
            });
        }
        mPopWindow.setData(categoryList.get(currentIndex).getChildren());
        mPopWindow.setDefItem(currentChildIndex);
        mBinding.ivPopup.setImageResource(R.mipmap.btn_shop_up);
        mPopWindow.showPopwindow0(mBinding.layoutTag);
    }
}
